package com.atmaowei.service.impl;

import com.atmaowei.entity.Login;
import com.atmaowei.entity.Student;
import com.atmaowei.entity.Teacher;
import com.atmaowei.mapper.LoginMapper;
import com.atmaowei.service.LoginService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class LoginServiceImpl implements LoginService {

    @Autowired
    private LoginMapper loginMapper;

    @Override
    public Login studentLogin(Login login) {
        return loginMapper.studentLogin(login);
    }

    @Override
    public Login teacherLogin(Login login) {
        return loginMapper.teacherLogin(login);
    }

    @Override
    public Login adminLogin(Login login) {
        return loginMapper.adminLogin(login);
    }

    @Override
    public Student checkSno(String sno) {
        return loginMapper.checkSno(sno);
    }

    @Override
    public Teacher checkTno(String tno) {
        return loginMapper.checkTno(tno);
    }

    @Override
    public boolean register(Login login) {
        if (checkSno(login.getUsername())==null && login.getUsertype().equals("学生")) {
            return false;
        }
        if (checkTno(login.getUsername())==null && login.getUsertype().equals("教师")) {
            return false;
        }
        loginMapper.register(login);
        return true;
    }

    @Override
    public Login findPassword(Login login) {
        if (checkSno(login.getUsername())==null && login.getUsertype().equals("学生")) {
            return null;
        }
        if (checkTno(login.getUsername())==null && login.getUsertype().equals("教师")) {
            return null;
        }
        return loginMapper.findPassword(login);
    }

    @Override
    public String checkStudentStatus(String sno) {
        return loginMapper.checkStudentStatus(sno);
    }

    @Override
    public String checkTeacherStatus(String tno) {
        return loginMapper.checkTeacherStatus(tno);
    }
}
